const { paramError } = require('../constant/status.type')

const validator = async (ctx, next) => {
  try {
    ctx.verifyParams({
      'goods_name': {
        type: 'string',
        require: true
      },
      'goods_price': {
        type: 'number',
        require: true
      },
      'goods_description': {
        type: 'string',
        require: true
      },
      'goods_category_id': {
        type: 'number',
        require: true
      },
      'goods_number': {
        type: 'number',
        require: true
      },
      'goods_img': {
        type: 'string',
        require: true
      }
    })
  } catch (error) {
    console.error(error, ' 商品参数校验错误');
    paramError.result = error
    return ctx.app.emit('error', paramError, ctx)
  }

  await next()
}

module.exports = {
  validator
}